#ifndef COMB_QUAL_HPP__
#define COMB_QUAL_HPP__

#include "util.hpp"

/** Generate rebinning index for a given call rates file in color space.
 * \param calls The call rates matrix.
 * \param read_length the length of reads.
 * \param orig_bin_cnt the number of quaility bins in calls
 * \param new_bin_cnt the new number of quality bins
 * \param new_bins A mapping from old to new scores for each position.
 */
void rebin_quals(const array_type5 &calls, unsigned int read_length, unsigned int orig_bin_cnt, unsigned int new_bin_cnt, boost::multi_array<int, 2> &new_bins);

/** Generate a new compressed call rates file using the rebinning boundaries from rebin_quals.
 * \param calls the original call rates.
 * \param new_bins rebinning info for each index.
 * \param read_length the length of the reads.
 * \param orig_bin_count the number of qualities in the original call rates array
 * \param new_bin_count the number of qualities in the new call rates array.
 * \param new_calls the new call rates array.
 */
void rebin_calls(const array_type5 &calls, const boost::multi_array<int, 2> &new_bins, unsigned int read_length, unsigned int orig_bin_cnt, unsigned int new_bin_cnt, array_type5 &new_calls);

/** Conver the counts matrix in call rates to probabilities for color space.
 * \param calls the call rates matrix, which will be filled with probabilities after this function.
 * \param read_length the size of the reads.
 * \param bin_cnt the number of bins in calls.
 */
void convert_call_rates_to_probs(array_type5 &calls, unsigned int read_length, unsigned int bin_cnt);

/** Generate rebinning index for a given call rates file in color space.
 * \param calls The call rates matrix.
 * \param read_length the length of reads.
 * \param orig_bin_cnt the number of quaility bins in calls
 * \param new_bin_cnt the new number of quality bins
 * \param new_bins A mapping from old to new scores for each position.
 */
void rebin_seq_quals(const array_type4 &calls, unsigned int read_length, unsigned int orig_bin_cnt, unsigned int new_bin_cnt, boost::multi_array<int, 2> &new_bins);

/** Generate a new compressed call rates file using the rebinning boundaries from rebin_seq_quals.
 * \param calls the original call rates.
 * \param new_bins rebinning info for each index.
 * \param read_length the length of the reads.
 * \param orig_bin_count the number of qualities in the original call rates array
 * \param new_bin_count the number of qualities in the new call rates array.
 * \param new_calls the new call rates array.
 */
void rebin_seq_calls(const array_type4 &calls, const boost::multi_array<int, 2> &new_bins, unsigned int read_length, unsigned int orig_bin_cnt, unsigned int new_bin_cnt, array_type4 &new_calls);


/** Conver the counts matrix in call rates to probabilities for sequence space.
 * \param calls the call rates matrix, which will be filled with probabilities after this function.
 * \param read_length the size of the reads.
 * \param bin_cnt the number of bins in calls.
 */
void convert_seq_call_rates_to_probs(array_type4 &calls, unsigned int read_length, unsigned int bin_cnt);
#endif
